import {
    LS_NAME,
    TAB_KEY_RU_MEN,
    TAB_KEY_TI_SHENG,
    TAB_KEY_QI_TA,
} from "../configs/index.js";
import {
    getLS,
} from "../utils/common.js";

export function setDemoIfn() {
    // localStorage.clear();
    const englishColze = getLS();
    [TAB_KEY_RU_MEN, TAB_KEY_TI_SHENG, TAB_KEY_QI_TA].forEach(
        (tabKey) => {
            const jsonFile = require(`./List_${tabKey}.js`);
            let itemObj = englishColze[tabKey];
            if (!itemObj) {
                Object.assign(englishColze, {
                    [tabKey]: {},
                });
                itemObj = englishColze[tabKey];
            }
            (jsonFile || []).forEach((item) => {
                const {
                    uploadTime,
                    fileTitle,
                    fileSubTitleZh,
                    fileSubTitleEn,
                    fileName,
                    audioId,
                    audioUrl,
                    totalTime,
                    jumpTimes,
                } = item;
                let jsFileText = require(`./file-list/${tabKey}/${fileName}.js`);
                let fileObj = itemObj[uploadTime];
                if (!fileObj) {
                    Object.assign(itemObj, {
                        [uploadTime]: {},
                    });
                    fileObj = itemObj[uploadTime];
                }
                Object.assign(fileObj, {
                    fileTitle,
                    fileSubTitleZh,
                    fileSubTitleEn,
                    fileText: jsFileText.default,
                    audioUrl,
                    totalTime,
                    jumpTimes,
                });
            });
        }
    );
    wx.setStorageSync(LS_NAME, englishColze);
}
